/**
 * This controller manages the User details view which are added as tabs (so multiple
 * instances are created). Each instance of the view creates an instance of this class to
 * control its behavior.
 */
Ext.define('DCApp.view.doc.DetailController', {
    extend: 'DCApp.controller.DetailController',
    alias: 'controller.docdetail',

    requires: [
        'Ext.window.Toast'
    ],
    config: {
        control: {
            'button[text=插入]': {
                click: 'onInsert'
            }
        }
    },
    onUploadDoc: function() {
    	var vw = this.getView();
		Ext.MessageBox.confirm('确认覆盖', '需要将原始文稿的文本提取到正文框吗?',
		function(btn, text){
			if(btn!='yes')
				return false;
    		var he = vw.down('htmleditor');
    		he.setValue("提取的纯文本1234");
		}, this);
    },
    onInsert:function(btn,e){
    	var vw = this.getView();
    	var he = vw.down('htmleditor');
    	var dv = btn.up('panel').down('dataview');
    	var sels = dv.getSelectionModel().getSelection();
    	var text="";
    	for(var i=0; i<sels.length; i++){
    		var url = sels[i].get('url');
    		if(url.indexOf('.jpg')!=-1)
    			text+='<img src="'+url+'"/>';
    		else
    			text+='<a href="'+url+'">'+ sels[i].get('name')+'</a>';
    	}
    	he.insertAtCursor(text);
    	he.focus();
    }
});
